Skip to content

fix(preview): unpack all three values returned by _auto_compile_prompts#1721

Open
fmferrari wants to merge 2 commits into
microsoft:mainfrom
fmferrari:fix/preview-too-many-values-to-unpack
Open

fix(preview): unpack all three values returned by _auto_compile_prompts#1721
fmferrari wants to merge 2 commits into
microsoft:mainfrom
fmferrari:fix/preview-too-many-values-to-unpack

Conversation

@fmferrari

Copy link
Copy Markdown

Problem

apm preview <script> crashes with:

ValueError: too many values to unpack (expected 2)

This happens for every script definition regardless of content.

Root Cause

_auto_compile_prompts() in src/apm_cli/core/script_runner.py has return type tuple[str, list[str], str] and always returns three values:

return compiled_command, compiled_prompt_files, runtime_content

_execute_script_command() correctly unpacks all three:

compiled_command, compiled_prompt_files, runtime_content = self._auto_compile_prompts(command, params)

But preview() in src/apm_cli/commands/run.py unpacks only two values in both its code paths:

  1. The rich-UI try block (line ~142)
  2. The except (ImportError, NameError) fallback path (line ~182)

Fix

Add _ to capture the unused runtime_content in both call-sites, matching how _execute_script_command already handles the return value. Preview does not execute the script, so runtime_content is not needed.

Reproduction

Any apm.yml with a scripts: block:

scripts:
  start: "echo hello"
$ apm preview start
Error previewing script: too many values to unpack (expected 2)

Tested against APM 0.19.0.

_auto_compile_prompts() returns a 3-tuple:
  (compiled_command, compiled_prompt_files, runtime_content)

The preview() command was unpacking only 2 values in both its rich-UI
path and its fallback except (ImportError, NameError) path, causing
apm preview to always crash with:

  ValueError: too many values to unpack (expected 2)

Fix: add _ to capture the unused runtime_content in both call-sites.
_execute_script_command already unpacks all three values correctly.

Fixes: apm preview <script> crashes for any script definition
Copilot AI review requested due to automatic review settings June 9, 2026 21:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the preview command to match an updated return signature from script_runner._auto_compile_prompts, preventing tuple-unpacking errors during command preview.

Changes:

  • Adjusts tuple unpacking to ignore the new third return value from _auto_compile_prompts.
  • Adds an inline comment documenting the updated return shape and why only the first two items are used.

Comment thread src/apm_cli/commands/run.py Outdated
Comment thread src/apm_cli/commands/run.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants